// forcetalk.txt
// Liek alknpc, but this character will aprroach and speak with character first time.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1 - Number of state when talked to. Plays default text if 0.
//   Cell 2,3 -  Stuff done flag. if it is 0, this character hunts party down
//   Cell 4 - Speaking range. Range pc is within to hunt down. Default to 12.
begincreaturescript;

variables;

short i,target;
short has_greeted = 0;
short speak_range = 12;
short last_abil;

body;

beginstate INIT_STATE;
	set_name(ME,"Caretaker Eloise");
	set_level(ME,28);
	set_boss_level(ME,1);
	
	if (get_memory_cell(4) > 0)
		speak_range = get_memory_cell(4);
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
break;

beginstate START_STATE;
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		set_state(3);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	if ((get_attitude(ME) >= 10) && (dist_to_pc() <= 40)) {
		set_foe_target(ME,pc_num());
		set_state(3);
		}
		
	if (my_dist_from_start() >= 6) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if (get_memory_cell(0) == 0)
			fidget(ME,20);
					
	if ((gf(34,3) > 0) && (get_flag(get_memory_cell(2),get_memory_cell(3)) == 0)) {
		approach_char(ME,pc_num(),1);
		set_state(4);
		}



break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((get_ran(1,0,100) < 70) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	

		  	place_particle_num(ME,1,4,8);
			print_named_str(ME,"surrounds herself with an aura of lightning.");
			pc_heard_sound_delay(179,250);						
	  		create_missile_spiral(147,40,7,2);
	  		damage_nearby(get_ran(get_level(ME) + get_attack_bonus(ME),1,8),7,1,0);
			status_nearby(get_level(ME) / 4,7,20,0);


		last_abil = get_current_tick();
		end();
		}
		
	do_attack();
break;

beginstate 4; // approaching pc
	if (get_flag(get_memory_cell(2),get_memory_cell(3)) > 0)
		set_state(START_STATE);
	if (get_attitude(ME) >= 10) {
		set_state(START_STATE);
		}
	if ((approach_char(ME,pc_num(),1)) || (dist_to_pc() <= 2)) {
		set_flag(get_memory_cell(2),get_memory_cell(3),1);
		begin_talk_mode(get_memory_cell(1));
		}
break;


beginstate TALKING_STATE;
	if (get_memory_cell(1) == 0) {
		print_str("Talking: You make a bit of small talk, but you don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(1));
break;